#include<iostream>
#include<vector>
#include<string>
using namespace std;

class Trie {
private:
    vector<Trie*> trieTree;
    bool isEnd;

    Trie* findPrefix(string word) {
        auto tmpPtr = this;
        for (auto e : word) {
            if (tmpPtr->trieTree[e - 'a'] == nullptr) {
                return nullptr;
            }
            tmpPtr = tmpPtr->trieTree[e - 'a'];
        }
        return tmpPtr;
    }
public:
    Trie() {
        isEnd = false;
        trieTree.resize(26, nullptr);
    }

    void insert(string word) {
        auto tmpPtr = this;
        for (auto e : word) {
            if (tmpPtr->trieTree[e - 'a'] == nullptr) {
                tmpPtr->trieTree[e - 'a'] = new Trie();
            }
            tmpPtr = tmpPtr->trieTree[e - 'a'];
        }
        tmpPtr->isEnd = true;
    }

    bool search(string word) {
        Trie* tmpPtr = this->findPrefix(word);
        return tmpPtr != nullptr && tmpPtr->isEnd;
    }

    bool startsWith(string prefix) {
        Trie* tmpPtr = this->findPrefix(prefix);
        return tmpPtr != nullptr;
    }

};

/**
 * Your Trie object will be instantiated and called as such:
 * Trie* obj = new Trie();
 * obj->insert(word);
 * bool param_2 = obj->search(word);
 * bool param_3 = obj->startsWith(prefix);
 */